<template>
  <div class="ChildPage TablePage" v-loading="loading">
    <vb-page ref="page">
      <template #table-data="scope">
        <div><el-button type="text" size="mini" @click="$refs.contentDialog.doShow(scope.row.data)">查看内容</el-button></div>
      </template>
      <template #table-success="scope">
        <el-tag :type="scope.row.success === true? 'success': 'danger'">{{ scope.row.success === true? '成功': '失败' }}</el-tag>
      </template>
      <template #table-handle-prepend="scope">
        <el-button size="mini" icon="el-icon-refresh-left" type="text" v-on:click="redoIntegrate(scope)" v-if="scope.row.success === false">重推</el-button>
      </template>
    </vb-page>
  </div>
  <ContentDialog ref="contentDialog"></ContentDialog>
</template>

<script>
import {getCurrentInstance} from "vue";
import ContentDialog from "./components/ContentDialog.vue";
export default {
  components: {
    ContentDialog
  },
  data() {
    return {}
  },
  setup() {
    const { proxy } = getCurrentInstance()
    // 获取状态名称
    const getStatusName = status => {
      if (!proxy.$refs.page.data || !proxy.$refs.page.data.config || !proxy.$refs.page.data.config.column) return ''

      let columns = proxy.$refs.page.data.config.column;
      for(let i = 0; i < columns.length; i++) {
        if (columns[i].prop === 'status') {
          let dicData = columns[i].dicData
          for(let j = 0; j < dicData.length; j++) {
            if (dicData[j].key === status) {
              return dicData[j].name
            }
          }
        }
      }
      return ''
    }
    return {
      getStatusName
    }
  },
  methods: {
    async redoIntegrate(scope) {
      try {
        this.loading = true
        await this.callApi("retry", {
          id: scope.row.id
        })
        this.$message.success('重推完成')
      } finally {
        this.$refs.page.data.reload()
        this.loading = false
      }
    },
  }

}
</script>

<style scoped>

</style>
